﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BaseLibrary
{
    public class SQlProcess
    {
        /// <summary>
        /// 时间格式处理$yyyyMM$--201208，yyyyMM+1---201209   ,$yyyyMMdd$---20120809
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        public static string DateProcess(string sql,DateTime d)
        {
            //yyyyMMddhhmmss

            string tmp = string.Empty;
            tmp = sql;
            tmp = tmp.Replace("$yyyyMM$", d.ToString("yyyyMM"));//201208
            tmp = tmp.Replace("$yyyyMM+1$", d.AddMonths(1).ToString("yyyyMM"));//201208            
            tmp = tmp.Replace("$yyyyMMdd$", d.ToString("yyyyMMdd"));//20120809
            tmp = tmp.Replace("$now$", d.ToString());
            return tmp;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static string DateProcess(string sql)
        {
            return DateProcess(sql, DateTime.Now);
        }
    }
}
